const fs = require('fs')
const path = require('path')

/**
 * 默认环境变量
 */
const envs = {
  BE_ORIGIN: 'https://ark.ddltech.top'
}

const envPath = path.resolve(__dirname, './.env')
if (fs.existsSync(envPath)) {
  try {
    const data = fs.readFileSync(envPath, 'utf8')

    const lines = data.split(/\n/)

    lines.forEach(line => {
      const res = /^\s*(\w+)=(.+)\s*/.exec(line)
      if (!res || !res[2]) return
      envs[res[1]] = res[2]
    })
    console.log(envs) // eslint-disable-line
  } catch (err) {
    console.error(err) // eslint-disable-line
  }
}

module.exports = envs
